package com.hz.erp.controller;

import com.alibaba.fastjson.JSONObject;
import com.hz.erp.constant.RetResponse;
import com.hz.erp.constant.RetResult;
import com.hz.erp.entity.page.PageResult;
import com.hz.erp.entity.vo.ObtainToken;
import com.hz.erp.entity.vo.TemInfoParameterVo;
import com.hz.erp.entity.vo.TemperatureInfoVo;
import com.hz.erp.enums.temperature.TemperatureEnum;
import com.hz.erp.service.TemInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author 柯鑫
 * @ClassName com.hz.erp.controller.TemInfoController
 * @description 温度信息Controller
 * @create 2020年06月09日 11:03
 */

@RestController
@RequestMapping("/user/temInfo")
@Api("温度信息Controller")
public class TemInfoController {


    @Autowired
    private TemInfoService temInfoService;

    /**
     * 根据分页条件查询所有用户数据
     * @param temInfoParameterVo
     * @return
     */
    @PostMapping("/findAllUserPage")
    @ApiOperation(value = "分页查询所有用户信息", notes="分页查询所有用户信息")
    public RetResult<PageResult> findUserPage(@RequestBody TemInfoParameterVo temInfoParameterVo, HttpServletRequest request){

        return temInfoService.selectTemInfoAllListByPage(temInfoParameterVo, request);
    }


    /**
     * 保存温度信息
     * @param TemperatureInfoVo
     * @return
     */
    @PostMapping("/saveTmpInfo")
    public RetResult<String> registerUser(@RequestBody TemperatureInfoVo TemperatureInfoVo){
        RetResult<String> retResult = temInfoService.insertTmpInfo(TemperatureInfoVo);
        return retResult;
    }


    /**
     * 解析token,将所有数据存库
     * @param jsonObject
     * @return
     */
    @PostMapping("/obtainToken")
    public RetResult<String> obtainToken(@RequestBody JSONObject jsonObject){

        return temInfoService.insertObtainTokenInfo(jsonObject);
    }

    /**
     * 获取体温状态下拉值
     * @return
     */
    @GetMapping("/getAllTemperature")
    public RetResult<Map<String, String>> getAllTemperature(){

        return RetResponse.makeOKRsp(TemperatureEnum.getAllKeyAndValue());
    }

    /**
     * 获取所有的UUID设备号
     * @return
     */
    @GetMapping("/selectAllTemUUID/{id}")
    public RetResult<List<String>> selectAllTemUUID(@PathVariable("id") Long id, HttpServletRequest request){
        return temInfoService.getAllTemUUID(id, request);
    }

    /**
     * @param response
     * @return
     */
    @GetMapping("/exportTmpInfo")
    public void exportTmpInfo(HttpServletResponse response, TemInfoParameterVo temInfoParameterVo, HttpServletRequest request){
         temInfoService.exportTmpInfo(response, temInfoParameterVo, request);
    }



}
